package com.study.config;

import com.google.common.base.Charsets;
import com.google.common.hash.Funnel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;

/**
 * @author study
 * @version 1.0
 * @date 2020/8/9 15:07
 * 布隆过滤器
 */
@Configuration
public class BloomFilterConfig {
    //初始化布隆过滤器，放入到spring容器里面
    @Bean(name = "bloomFilterHelper")
    public BloomFilterHelper<String> initbloomFilterHelper() {
        //Charsets.UTF_8
        return new BloomFilterHelper<>((Funnel<String>) (from, into) ->
                into.putString(from, StandardCharsets.UTF_8).putString(from, Charsets.UTF_8), 1000000, 0.01);
    }

}
